package com.haotunet.app.goldtreasure.views;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.utils.ActivityUtils;

public class CampaignDialog extends Dialog implements android.view.View.OnClickListener {
    private LayoutInflater mLayoutInflater;
    private Context mcontext;
    private View rootView;
    private ImageView ivPopupImage;
    private String mPopupImageUrl;
    private String mLinkUrl;

    public CampaignDialog(Context context, String popupImageUrl, String linkUrl, int theme) {
        super(context, theme);
        this.mcontext = context;
        this.mPopupImageUrl = popupImageUrl;
        this.mLinkUrl = linkUrl;
        mLayoutInflater = (LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        initViews();
    }

    private void initViews() {
        rootView = mLayoutInflater.inflate(R.layout.dialog_activity, null);
        setContentView(rootView);
        ivPopupImage = (ImageView) rootView.findViewById(R.id.popup_image);
        Glide.with(mcontext).load(mPopupImageUrl).placeholder(R.drawable.popup_placeholder).error(R.drawable.popup_placeholder).into(ivPopupImage);
        ivPopupImage.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.popup_image:
                if (TextUtils.isEmpty(mLinkUrl)) {
                    ActivityUtils.gotoRegister(mcontext);
                } else {
                    ActivityUtils.gotoDynamicDetail(mcontext, mLinkUrl, 0);
                }
                dismiss();
                break;
            default:
                break;
        }
    }

}
